<!-- components/Analytics.vue -->
<script setup>
import { useTaskStore } from '@/stores/taskStore'
import { computed } from 'vue'

const store = useTaskStore()

const analytics = computed(() => {
  const totalTasks = store.tasks.value.length
  const completedTasks = store.tasksByStatus.done.length
  const completionRate = totalTasks > 0 
    ? Math.round((completedTasks / totalTasks) * 100) 
    : 0
  
  // 成员工作效率分析
  const memberEfficiency = store.members.value.map(member => {
    const tasksCompleted = store.tasks.value.filter(
      t => t.assignedTo === member.id && t.status === 'done'
    ).length
    return {
      name: member.name,
      efficiency: member.capacity > 0 
        ? Math.round((tasksCompleted / member.capacity) * 100)
        : 0
    }
  })
  
  return { totalTasks, completionRate, memberEfficiency }
})
</script>

<template>
  <div class="analytics">
    <h3>项目分析</h3>
    <div class="stats">
      <div class="stat-card">
        <h4>总任务数</h4>
        <p>{{ analytics.totalTasks }}</p>
      </div>
      <div class="stat-card">
        <h4>完成率</h4>
        <p>{{ analytics.completionRate }}%</p>
      </div>
    </div>
    
    <h4>成员效率</h4>
    <ul>
      <li v-for="member in analytics.memberEfficiency" :key="member.name">
        {{ member.name }}: {{ member.efficiency }}%
      </li>
    </ul>
  </div>
</template>